package com.kai.service.message.controller;

import com.kai.service.data.PagingResult;
import com.kai.service.data.Result;
import com.kai.service.data.request.message.MessageBoardRequest;
import com.kai.service.data.request.message.PagingMessageBoardRequest;
import com.kai.service.data.response.message.MessageBoardResponse;
import com.kai.service.message.service.IMessageBoardService;
import com.kai.service.util.ResultResponseUtil;
import io.swagger.v3.oas.annotations.Operation;
import io.swagger.v3.oas.annotations.tags.Tag;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;

@RestController
@RequestMapping("/message/board")
@Tag(name = "留言板")
public class MessageBoardController {

    @Autowired
    private IMessageBoardService messageBoardService;

    /**
     * 添加留言
     *
     * @param messageBoardRequest
     * @return
     */
    @PostMapping
    @Operation(summary = "添加留言")
    public Result<MessageBoardResponse> createMessage(@RequestBody MessageBoardRequest messageBoardRequest){
        return ResultResponseUtil.success(messageBoardService.createMessage(messageBoardRequest));
    }

    /**
     * 分页查询留言
     *
     * @param pagingMessageBoardRequest
     * @return
     */
    @PostMapping("/paging")
    @Operation(summary = "分页查询留言")
    public PagingResult<MessageBoardResponse> pagingMessage(@RequestBody PagingMessageBoardRequest pagingMessageBoardRequest){
        return ResultResponseUtil.pageSuccess(messageBoardService.pagingMessage(pagingMessageBoardRequest));
    }

    /**
     * 修改留言
     *
     * @param messageId
     * @param messageBoardRequest
     * @return
     */
    @PutMapping("/{messageId}")
    @Operation(summary = "修改留言")
    public Result<Boolean> updateMessage(@PathVariable("messageId") Integer messageId, @RequestBody MessageBoardRequest messageBoardRequest){
        return ResultResponseUtil.success(messageBoardService.updateMessage(messageId, messageBoardRequest));
    }

    /**
     * 删除留言
     *
     * @param messageId
     * @return
     */
    @DeleteMapping("/{messageId}")
    @Operation(summary = "删除留言")
    public Result<Boolean> deleteMessage(@PathVariable("messageId") Integer messageId){
        return ResultResponseUtil.success(messageBoardService.deleteMessage(messageId));
    }
}
